<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义指令</title>
</head>
<script type="text/javascript" src="../js/vue.js"></script>
<body>
<div id="root">
    <h2>当前的n值是：<span v-text="n"></span></h2><br>
    <h2>放大十倍的n值是：<span v-big="n"></span></h2>
    <button @click="n++">点我n加一</button>
    <hr>
    <input type="text" :value="n">
    <input type="text" v-fbind:value="n">
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip=false //阻止vue在启动时生成生产提示

    new Vue({
        el:'#root',
        data:{
           n:1,
        },
        directives:{
            big(element,binding) {
            element.innerText = binding.value * 10
            },
            fbind:{
                //一上来就绑定
                bind(element,binding){
                    element.value = binding.value
                },
                //插入时
                inserted(element,binding){
                    element.focus()
                },
                //重新解析时
                update(element,binding){
                    element.value = binding.value
                }
            }
        }
    })
</script>
</html>